<template>
  <div class="playBox">
    <div class="listTop">
      <div class="listTopBg">
        <img :src="$root.musicStore.picUrl" />
      </div>
      <div class="listTopContext">
        <img :src="$root.musicStore.picUrl" />
        <div class="text">{{ $root.musicStore.text }}</div>
      </div>
    </div>
    <Loading v-if="songDetail.length == 0"></Loading>
    <ul class="newsong" v-if="songDetail.length > 0">
      <p>歌单列表</p>
      <li class="li" v-for="(s, index) in songDetail" :key="s.id">
        <span>{{ (index + 1) | formatNum }}</span>
        <SongItem :item="s"></SongItem>
      </li>
      <p class="commentP">评论区</p>

      <li class="li" v-for="(s, index) in comments" :key="index">
        <HotComments :item="s" v-if="comments.length > 0"></HotComments>
      </li>
      <template v-if="comments.length <= 0">
        <p class="textComments">暂无评论....</p></template
      >
    </ul>
    <div
      :style="{ paddingBottom: $root.musicStore.musicID ? '50px' : '0' }"
    ></div>
  </div>
</template>

<script>
import SongItem from "@/components/SongItem";
import Loading from "@/components/Loading";
import HotComments from "@/components/HotComments";
export default {
  name: "PlayList",
  components: {
    SongItem,
    Loading,
    HotComments,
  },
  data() {
    return {
      listID: null,
      songList: [],
      str: "",
      songDetail: [],
      comments: [],
    };
  },

  created() {
    this.listID = this.$route.params.id;
    this.$root.musicStore.picUrl = this.$route.query.item.picUrl;
    this.$root.musicStore.text = this.$route.query.item.name;

    this.$axios
      .get("/playlist/detail?id=" + this.listID)
      .then((data) => {
        this.songList = data.data.playlist.trackIds;
        // console.log(data);
        this.songList.forEach((item, index) => {
          if (index == this.songList.length - 1) {
            this.str += item.id;
          } else {
            this.str += item.id + ",";
          }
        });
        return this.str;
      })
      .then((str) => {
        this.$axios
          // .get("http://music.kele8.cn/song/detail?ids=" + str)
          .get("/song/detail?ids=" + str)
          .then((data) => {
            this.songDetail = data.data.songs;
          });
      });

    this.$axios.get("/comment/playlist?id=" + this.listID).then((data) => {
      this.comments = data.data.hotComments;
      console.log(this.comments);
    });
  },
  filters: {
    formatNum(val) {
      if (val < 10) {
        return "0" + val;
      } else {
        return val;
      }
    },
  },
};
</script>

<style lang="less" scoped>
.newsong {
  .commentP {
    padding: 1vw;
  }
  p {
    font-size: 12px;
    margin: 5px 0 5px 5px;
    color: rgb(255,208,0);
  }
  .textComments {
    text-align: center;
    padding: 2vw;
    font-size: 16px;
  }
}
.listTop {
  overflow: hidden;
  width: 100vw;
  height: 200px;
  display: flex;
  padding: 0 20px;
  background-color: rgba(0, 0, 0, 0.25);
  justify-content: flex-start;
  align-items: center;
  position: relative;
  .listTopBg {
    width: 100vw;
    height: 200px;
    position: absolute;
    top: 0;
    left: 0;
    -webkit-filter: blur(15px);
    -moz-filter: blur(15px);
    -o-filter: blur(15px);
    -ms-filter: blur(15px);
    filter: blur(15px);
    img {
      height: 100%;
      width: 100%;
    }
  }
  .listTopContext {
    padding: 5vw;
    display: flex;
    width: 100%;
    top: 100%;
    position: absolute;
    left: 0;
    top: 0;
    img {
      width: 145px;
      height: 145px;
    }
    .text {
      color: white;
      text-shadow: 0 0 2px black;
      align-self: center;
      flex: 1;
      padding: 0 20px;
      font-size: 18px;
    }
  }
}
.li {
  display: flex;

  span{
  padding: 5px 8px;
  }
  &:first-of-type {
    span {
      color: rgb(255, 251, 0);
    }
  }
  &:nth-of-type(2) {
    span {
      color: rgb(245, 241, 7);
    }
  }
  &:nth-of-type(3) {
    span {
      color: rgb(230, 192, 23);
    }
  }
  span {
    display: inline-block;
    line-height: 50px;
    margin: 0 8px;
    color: rgb(148, 139, 93);
  }

  div {
    flex: 1;
  }
}
</style>
